/*
 * @Author: jiu yin
 * @Date: 2023-12-18 19:13:21
 * @LastEditTime: 2024-01-16 11:58:31
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \association-service-web-admin\src\comment\FormTwo\utils.ts
 * jiu
 */

/**
 * @description:
 * @param {string} item_str //formList的name
 * @param {any} item //修改的属性
 * @return {*}
 */
export const setFormList_fn = (
   setFormList: Function,
   item_str: string,
   item: any = {}
): any => {
   setFormList((formList: any) => {
      let findIndex = formList.findIndex((item: any) => item.name == item_str);
      for (let key in item) {
         formList[findIndex][key] = item[key];
      }
      return [...formList];
   });
};

/**
 * @description:针对nest_item的children
 * @param {string} item_str //formList的name
 * @param {string} children_name //item_str的children的name
 * @param {any} item //修改的属性
 * @return {*}
 */
export const setFormList_nest_item_fn = (
   setFormList: Function,
   item_str: string,
   children_name: string,
   item: any = {}
): any => {
   setFormList((formList: any) => {
      let findIndex = formList.findIndex((item: any) => item.name == item_str);
      let children_findIndex = formList[findIndex].children.findIndex(
         (item: any) => item.name == children_name
      );
      for (let key in item) {
         formList[findIndex].children[children_findIndex][key] = item[key];
      }
      return [...formList];
   });
};
